﻿using Glorysoft.Auto.Xfw;
using Glorysoft.EAP.Core;
using Glorysoft.EAP.Core.Entities;
using Glorysoft.EAP.Core.Enums;
using Glorysoft.EAP.EAPClient.Common;
using Glorysoft.EAP.EAPClient.Model;
using Serilog.Core;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Windows;

namespace Glorysoft.EAP.EAPClient
{
    public class ClientService : AbstractService
    {
        private readonly Logger logger;
        private readonly Logger Dblogger;
        private C_LotInfo c_LotInfo = null;
        public ClientService()
        {
            logger = XfwContext.EapLogger;
            Dblogger = XfwContext.DbLogger;
            c_LotInfo = new C_LotInfo();
        }
        [DllImport("winmm.dll")]
        public static extern bool PlaySound(String Filename, int Mod, int Flags);

        public Model.RunService ClientInfo
        {
            get
            {
                return Model.RunService.Current;
            }
        }
        /// <summary>
        /// Server启动后，每台连接设备初始化时候收到的消息
        /// </summary>
        /// <param name="xfwArgs"></param>
        public void NotifyClientConn(XfwArgs xfwArgs)
        {
            try
            {
                var obj = xfwArgs.NATSData.Data;
                var body = obj.GetBody();
                var eqpId = body.GetVal(CItems.EqpID);
                var eapStatus = body.GetVal(CItems.CommState);
            }
            catch (Exception ex)
            {
                logger.Error(ex, $"ClientService.NotifyClientConn() Execute Error.");
            }
        }
        public void SendWaferEnd(XfwArgs xfwArgs)
        {
            try
            {
                var obj = xfwArgs.NATSData.Data;
                var body = obj.GetBody();
                var eqpId = body.GetVal(CItems.EqpID);
                var waferId = body.GetVal(CItems.waferId);
                var passNo = body.GetVal(CItems.PassDieCount);
                var position = waferId.Substring(waferId.Length - 2);
                //ClientInfo.EQPInfo.LotList[0].State = lotStatus;
                var waferinfo = ClientInfo.EQPInfo.LotList[0].SlotMaps.FirstOrDefault(o => waferId.Contains(o.waferId.Replace("#","-")));
                if (waferinfo == null) return;
                waferinfo.passNo = int.Parse(passNo);
                waferinfo.waferState = WaferState.WaferEnd.ToString();
            }
            catch (Exception ex)
            {
                logger.Error(ex, $"ClientService.SendLotEnd() Execute Error.");
            }
        }
        public void NotifyDisconnect(XfwArgs xfwArgs)
        {
            try
            {
                var obj = xfwArgs.NATSData.Data;
                var body = obj.GetBody();
                ClientInfo.EQPInfo.ConnStatus = false;
                Dict.Current.EAPConnStatus = "1";
                var messages = TranslateMsg.GetTranslation("DisConn", "EAPServer");
                if (!(messages == null || messages.Count == 0))
                {
                    ClientInfo.EQPInfo.LotList[0].ShowMsg(MessageOrigin.EAP, MessageType.Error, messages[RunService.Current.ClientLanguage]);
                    Dblogger.Information("EAPClient Tip:" + messages[RunService.Current.ClientLanguage]);
                }
                ClientInfo.EQPInfo.ProberStatus = false;
                messages = TranslateMsg.GetTranslation("DisConn", "OCR");
                if (!(messages == null || messages.Count == 0))
                {
                    ClientInfo.EQPInfo.LotList[0].ShowMsg(MessageOrigin.EAP, MessageType.Error, messages[RunService.Current.ClientLanguage]);
                    Dblogger.Information("EAPClient Tip:" + messages[RunService.Current.ClientLanguage]);
                }
                ClientInfo.EQPInfo.TesterStatus = false;
                messages = TranslateMsg.GetTranslation("DisConn", "Daemon");
                if (!(messages == null || messages.Count == 0))
                {
                    ClientInfo.EQPInfo.LotList[0].ShowMsg(MessageOrigin.EAP, MessageType.Error, messages[RunService.Current.ClientLanguage]);
                    Dblogger.Information("EAPClient Tip:" + messages[RunService.Current.ClientLanguage]);
                }
                c_LotInfo.Clear("1");
            }
            catch (Exception ex)
            {
                logger.Error(ex, $"ClientService.NotifyClientConn() Execute Error.");
            }
        }
        public void ReceiveConnectStatus(XfwArgs xfwArgs)
        {
            try
            {
                var obj = xfwArgs.NATSData.Data;
                var body = obj.GetBody();
                var eqpId = body.GetVal(CItems.EqpID);
                var eapStatus = body.GetVal(CItems.EqpStatus);
                if (RunService.Current.EquipmentList.Count > 0)
                {
                    foreach (EqpClientInfo entity in RunService.Current.EquipmentList)
                    {
                        if (eqpId == entity.EqpName)
                        {
                            entity.ConnStatus = true;
                            if (Convert.ToInt32(eapStatus) == (int)EQPConnectionState.Connected)
                                entity.EQPConnStatus = true;
                            else
                                entity.EQPConnStatus = false;
                            if (!entity.EQPConnStatus)
                                PlaySound(AppDomain.CurrentDomain.BaseDirectory + "\\HOOK1.WAV", 0, 1);
                            if (RunService.Current.MIDStatus.ContainsKey(eqpId))
                                RunService.Current.MIDStatus[eqpId] = true;
                            else
                                RunService.Current.MIDStatus.Add(eqpId, true);
                        }
                    }
                }
                EAPClient client = new EAPClient();
                client.ChangeLanguage(RunService.Current.ClientLanguage);
            }
            catch (Exception ex)
            {
                logger.Error(ex, $"ClientService.ReceiveConnect() Execute Error.");
            }
        }
        public void ShowMessage(XfwArgs xfwArgs)
        {
            try
            {
                var obj = xfwArgs.NATSData.Data;
                var body = obj.GetBody();
                var eqpId = body.GetVal(CItems.EqpID);
                var messages = body.GetVal1<Dictionary<string, string>>(CItems.TerminalMessage);
                var type = body.GetVal(CItems.MessageType);
                var messageOrigin = body.GetVal(CItems.MessageOrigin);
                ClientInfo.EQPInfo.LotList[0].ShowMsg(MessageOrigin.EAP, (MessageType)Enum.Parse(typeof(MessageType), type), messages[RunService.Current.ClientLanguage]);
                Dblogger.Information("EAPClient Tip:" + messages[RunService.Current.ClientLanguage]);
            }
            catch (Exception ex)
            {
                logger.Error(ex, $"ClientService.ShowMessage() Execute Error.");
            }
        }
        public void ShowAlarmMessage(XfwArgs xfwArgs)
        {
            try
            {
                var obj = xfwArgs.NATSData.Data;
                var body = obj.GetBody();
                var eqpId = body.GetVal(CItems.EqpID);
                var AlarmMessage = body.GetVal(CItems.AlarmMessage);
                var messages = body.GetVal1<Dictionary<string, string>>(CItems.TerminalMessage);
                var type = body.GetVal(CItems.MessageType);
                var messageOrigin = body.GetVal(CItems.MessageOrigin);
                var current_msg = messages[RunService.Current.ClientLanguage];
                if (type == MessageType.Alarm.ToString() && messages.Count > 0)
                {
                    ClientInfo.EQPInfo.LotList[0].ShowMsg(MessageOrigin.EAP, (MessageType)Enum.Parse(typeof(MessageType), type), messages[RunService.Current.ClientLanguage]);
                    Dblogger.Information("EAPClient Tip:" + messages[RunService.Current.ClientLanguage]);
                    Application.Current.Dispatcher.Invoke(new Action(() =>
                    {
                        AlarmMessageBox.Show(messages[RunService.Current.ClientLanguage]);
                    }));

                    logger.Debug($"收到RPA报警信息:{messages[RunService.Current.ClientLanguage]}");
                    //ClientInfo.EQPInfo.Eaprun = Visibility.Collapsed;
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex, $"ClientService.SendLotStatus() Execute Error.");
            }
        }
        public void ShowConfrimNeedMarkResult(XfwArgs xfwArgs)
        {
            try
            {
                var obj = xfwArgs.NATSData.Data;
                var body = obj.GetBody();
                var eqpId = body.GetVal(CItems.EqpID);
                var messages = body.GetVal1<Dictionary<string, string>>(CItems.TerminalMessage);
                var type = body.GetVal(CItems.MessageType);
                var messageOrigin = body.GetVal(CItems.MessageOrigin);
                var needletype = body.GetVal(CItems.NeedleType);
                Dict.Current.NeedleMaterial = needletype;
                ClientInfo.EQPInfo.LotList[0].ShowMsg(MessageOrigin.EAP, (MessageType)Enum.Parse(typeof(MessageType), type), messages[RunService.Current.ClientLanguage]);
                Dblogger.Information("EAPClient Tip:" + messages[RunService.Current.ClientLanguage]);
                c_LotInfo.NeedleMarkDetectionUserLogin();
            }
            catch (Exception ex)
            {
                logger.Error(ex, $"ClientService.ShowMessage() Execute Error.");
            }
        }

        public void SendLotInfo(XfwArgs xfwArgs)
        {
            try
            {
                var obj = xfwArgs.NATSData.Data;
                var body = obj.GetBody();
                var eqpId = body.GetVal(CItems.EqpID);
                var portId = body.GetVal(CItems.PortID);
                var CarrierId = body.GetVal(CItems.CarrierID);
                var _lots = body.GetVal1<LotInfo>(CItems.LotInfo);
                var _lot = _lots;
                if (RunService.Current.EquipmentList.Count > 0)
                {
                    foreach (EqpClientInfo entity in RunService.Current.EquipmentList)
                    {
                        if (eqpId == entity.EqpName)
                        {
                            for (int i = 0; i < entity.LotList.Count; i++)
                            {
                                if (entity.LotList[i].portid == portId)
                                {
                                    entity.LotList[i].CarrierId = CarrierId;
                                    entity.LotList[i].LotId = _lot.LotId;
                                    entity.LotList[i].RealLotId = _lot.LotId;
                                    entity.LotList[i].RecipeId = _lot.RecipeId;
                                    entity.LotList[i].ProductId = _lot.ProductId;
                                    entity.LotList[i].LotStatus = _lot.RunStatus;
                                    entity.LotList[i].TotalWafers = _lot.Qty.ToString();
                                    entity.LotList[i].LotVis = Visibility.Visible;
                                    entity.LotList[i].Productver = _lot.ProductVer;
                                    entity.LotList[i].MoveinTime = _lot.TrackInTime;
                                    entity.LotList[i].MoveoutTime = _lot.TrackOutTime;
                                    entity.LotList[i].LOSSINFOLIST = _lot.LOSSINFOLIST;
                                    entity.LotList[i].UNITLIST = _lot.UNITLIST;
                                    if (_lot.IsPodPlaced)
                                        entity.LotList[i].CassetteVis = Visibility.Visible;

                                    if (_lot.CurrentCarreir.Units.Count > 0)
                                    {
                                        foreach (var map in _lot.CurrentCarreir.Units)
                                        {
                                            if (map != null)
                                            {
                                                //if (string.IsNullOrEmpty(map.UnitColor))
                                                //  entity.LotList[i].SlotMaps[Convert.ToInt32(map.Position) - 1].SlotColor = "Red";
                                                //else
                                                //  entity.LotList[i].SlotMaps[Convert.ToInt32(map.Position) - 1].SlotColor = map.UnitColor;
                                                //entity.LotList[i].SlotMaps[Convert.ToInt32(map.Position) - 1].WaferId = map.UnitId;
                                            }
                                        }
                                    }
                                    break;
                                }
                            }
                            entity.RGYColor = entity.CheckRGY(ProcessState.Waitting);
                            if (entity.IsMouseOver == false)
                                RunService.Current.RGYChanged(entity.RGYColor);
                            break;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex, $"ClientService.SendLotInfo() Execute Error.");
            }
        }
        /// <summary>
        /// 将login用户名显示Client
        /// </summary>
        /// <param name="xfwArgs"></param>
        public void SendUserId(XfwArgs xfwArgs)
        {
            try
            {
                var obj = xfwArgs.NATSData.Data;
                var body = obj.GetBody();
                var userId = body.GetVal(CItems.UserID);
                RunService.Current.Name = userId;
                var eqpId = body.GetVal(CItems.EqpID);
                var portId = body.GetVal(CItems.PortID);
                if (RunService.Current.EquipmentList.Count > 0)
                {
                    foreach (EqpClientInfo entity in RunService.Current.EquipmentList)
                    {
                        if (eqpId == entity.EqpName)
                        {
                            for (int i = 0; i < entity.LotList.Count; i++)
                            {
                                if (entity.LotList[i].portid == portId)
                                {
                                    entity.LotList[i].UserId = userId.ToUpper();
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex, $"ClientService.SendUserId() Execute Error.");
            }
        }
        /// <summary>
        /// 清空多个magazine的记录
        /// </summary>
        /// <param name="xfwArgs"></param>
        public void SendMagazineClear(XfwArgs xfwArgs)
        {
            try
            {
                var obj = xfwArgs.NATSData.Data;
                var body = obj.GetBody();
                var eqpId = body.GetVal(CItems.EqpID);
                if (EQPStatus.MagazineList.Contains(eqpId))
                    MainWindow.magazineDic.Remove(eqpId);
            }
            catch (Exception ex)
            {
                logger.Error(ex, $"ClientService.SendMagazineClear() Execute Error.");
            }
        }
        /// <summary>
        /// 清除当前批次信息
        /// </summary>
        /// <param name="xfwArgs"></param>
        public void RemoveLotInfo(XfwArgs xfwArgs)
        {
            try
            {
                var obj = xfwArgs.NATSData.Data;
                var body = obj.GetBody();
                var eqpId = body.GetVal(CItems.EqpID);
                //ClientInfo.EQPInfo.LotList[0].LotId = string.Empty;
                //ClientInfo.EQPInfo.LotList[0].Qty = string.Empty;
                //ClientInfo.EQPInfo.LotList[0].State = string.Empty;
                //ClientInfo.EQPInfo.LotList[0].ProductId = string.Empty;
                //ClientInfo.EQPInfo.LotList[0].ProberRecipe = string.Empty;
                //ClientInfo.EQPInfo.LotList[0].TesterProgram = string.Empty;
                //ClientInfo.EQPInfo.LotList[0].Probercard = string.Empty;
                //ClientInfo.EQPInfo.LotList[0].LotsStatus= string.Empty;
                //ClientInfo.EQPInfo.LotList[0].StageId= string.Empty;
                //ClientInfo.EQPInfo.LotList[0].Priority= string.Empty;
                //ClientInfo.EQPInfo.LotList[0].SlotMaps = null;
                //ClientInfo.EQPInfo.LotList[0].UNITLIST = null;
                //ClientInfo.EQPInfo.BtnOk = Visibility.Visible;
                c_LotInfo.Clear();
                //var portId = body.GetVal(CItems.PortID);
                //if (RunService.Current.EquipmentList.Count > 0)
                //{
                //    for (int j = 0; j < RunService.Current.EquipmentList.Count; j++)
                //    {
                //        if (eqpId == RunService.Current.EquipmentList[j].EqpName)
                //        {
                //            for (int i = 0; i < RunService.Current.EquipmentList[j].LotList.Count; i++)
                //            {
                //                if (RunService.Current.EquipmentList[j].LotList[i].portid == portId)
                //                    RunService.Current.EquipmentList[j].LotList[i].Clear();
                //            }
                //            if (EQPStatus.MagazineList.Contains(EQPStatus.currenteqpid))
                //                MainWindow.magazineDic.Remove(EQPStatus.currenteqpid);
                //            if (EQPStatus.TrayList.Contains(EQPStatus.currenteqpid))
                //            {
                //                MainWindow.trayDic.Remove(EQPStatus.currenteqpid);
                //            }
                //            if (EQPStatus.TrayTransferList.Contains(EQPStatus.currenteqpid))
                //            {
                //                MainWindow.traytransferDic.Remove(EQPStatus.currenteqpid);
                //            }
                //            RunService.Current.EquipmentList[j].RGYColor = RunService.Current.EquipmentList[j].CheckRGY(ProcessState.UnKnow);
                //            if (RunService.Current.EquipmentList[j].IsMouseOver == false)
                //                RunService.Current.RGYChanged(RunService.Current.EquipmentList[j].RGYColor);
                //            break;
                //        }
                //    }
                //}
            }
            catch (Exception ex)
            {
                logger.Error(ex, $"ClientService.RemoveLotInfo() Execute Error.");
            }
        }
        /// <summary>
        /// 更改界面上面Cassette显示状态
        /// </summary>
        /// <param name="xfwArgs"></param>
        public void PodPlaced(XfwArgs xfwArgs)
        {
            try
            {
                var obj = xfwArgs.NATSData.Data;
                var body = obj.GetBody();
                var eqpId = body.GetVal(CItems.EqpID);
                var portId = body.GetVal(CItems.PortID);
                if (RunService.Current.EquipmentList.Count > 0)
                {
                    foreach (EqpClientInfo entity in RunService.Current.EquipmentList)
                    {
                        if (eqpId == entity.EqpName)
                        {
                            for (int i = 0; i < entity.LotList.Count; i++)
                            {
                                if (entity.LotList[i].portid == portId)
                                {
                                    entity.LotList[i].CassetteVis = Visibility.Visible;
                                }
                            }
                            entity.RGYColor = entity.CheckRGY(ProcessState.UnKnow);
                            if (entity.IsMouseOver == false)
                                RunService.Current.RGYChanged(entity.RGYColor);
                            break;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex, $"ClientService.PodPlaced() Execute Error.");
            }
        }
        public void SendProcessState(XfwArgs xfwArgs)
        {
            try
            {
                var obj = xfwArgs.NATSData.Data;
                var body = obj.GetBody();
                var eqpId = body.GetVal(CItems.EqpID);
                var portId = body.GetVal(CItems.PortID);
                var processState = body.GetVal(CItems.ProcessState);
                var state = (ProcessState)Enum.Parse(typeof(ProcessState), processState);
                if (RunService.Current.EquipmentList.Count > 0)
                {
                    foreach (EqpClientInfo entity in RunService.Current.EquipmentList)
                    {
                        if (eqpId == entity.EqpName)
                        {
                            for (int i = 0; i < entity.LotList.Count; i++)
                            {
                                if (entity.LotList[i].portid == portId)
                                {
                                    entity.LotList[i].LotStatus = state;

                                }
                            }
                            entity.RGYColor = entity.CheckRGY(state);
                            if (entity.IsMouseOver == false)
                                RunService.Current.RGYChanged(entity.RGYColor);
                            break;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex, $"ClientService.SendProcessState() Execute Error.");
            }
        }

        /// <summary>
        /// 改变片子的颜色
        /// </summary>
        /// <param name="xfwArgs"></param>
        public void ChangeWaferColor(XfwArgs xfwArgs)
        {
            try
            {
                var obj = xfwArgs.NATSData.Data;
                var body = obj.GetBody();
                var eqpId = body.GetVal(CItems.EqpID);
                var portId = body.GetVal(CItems.PortID);
                var unitInfo = body.GetVal<UnitInfo>(CItems.UnitInfo);
                if (RunService.Current.EquipmentList.Count > 0)
                {
                    foreach (EqpClientInfo entity in RunService.Current.EquipmentList)
                    {
                        if (eqpId == entity.EqpName)
                        {
                            for (int i = 0; i < entity.LotList.Count; i++)
                            {
                                if (entity.LotList[i].portid == portId)
                                {
                                    if (entity.LotList[i].SlotMaps.Count > 0)
                                    {
                                        foreach (var map in entity.LotList[i].SlotMaps)
                                        {
                                            if (map != null && map.SlotId == unitInfo.Position)
                                            {
                                                //   map.SlotColor = unitInfo.UnitColor;
                                                break;
                                            }
                                        }
                                    }
                                    break;
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex, $"ClientService.ChangeWaferColor() Execute Error.");
            }
        }

        /// <summary>
        /// 服务端上报的设备状态
        /// </summary>
        /// <param name="xfwArgs"></param>
        public void EqpStatusReport(XfwArgs xfwArgs)
        {
            try
            {
                var obj = xfwArgs.NATSData.Data;
                var body = obj.GetBody();
                var eqpId = body.GetVal(CItems.EqpID);
                var eapstatus = body.GetVal(CItems.EqpStatus);
                //TODP:委托事件实现前端显示实时状态
                if (ClientInfo.EQPInfo.ProberName == eqpId) //Prober连接状态
                {
                    var conn = ClientInfo.EQPInfo.ProberStatus ? "1" : "-1";
                    if (conn == eapstatus)
                    {
                        return;
                    }
                    if (eapstatus == "1")
                    {
                        ClientInfo.EQPInfo.ProberStatus = true;
                        var messages = TranslateMsg.GetTranslation("Conn", "OCR");
                        if (!(messages == null || messages.Count == 0))
                        {
                            ClientInfo.EQPInfo.LotList[0].ShowMsg(MessageOrigin.EAP, MessageType.Conn, messages[RunService.Current.ClientLanguage]);
                            Dblogger.Information("EAPClient Tip:" + messages[RunService.Current.ClientLanguage]);
                        }
                    }
                    else
                    {
                        ClientInfo.EQPInfo.ProberStatus = false;
                        var messages = TranslateMsg.GetTranslation("DisConn", "OCR");
                        if (!(messages == null || messages.Count == 0))
                        {
                            ClientInfo.EQPInfo.LotList[0].ShowMsg(MessageOrigin.EAP, MessageType.Error, messages[RunService.Current.ClientLanguage]);
                            Dblogger.Information("EAPClient Tip:" + messages[RunService.Current.ClientLanguage]);
                        }
                    }
                }
                else if (ClientInfo.EQPInfo.TesterName == eqpId) //Tester连接状态
                {
                    var conn = ClientInfo.EQPInfo.TesterStatus ? "1" : "-1";
                    if (conn == eapstatus || string.IsNullOrEmpty(eapstatus))
                    {
                        return;
                    }
                    if (eapstatus == "1")
                    {
                        ClientInfo.EQPInfo.TesterStatus = true;
                        var messages = TranslateMsg.GetTranslation("Conn", "Daemon");
                        if (!(messages == null || messages.Count == 0))
                        {
                            ClientInfo.EQPInfo.LotList[0].ShowMsg(MessageOrigin.EAP, MessageType.Conn, messages[RunService.Current.ClientLanguage]);
                            Dblogger.Information("EAPClient Tip:" + messages[RunService.Current.ClientLanguage]);
                        }
                    }
                    else
                    {
                        ClientInfo.EQPInfo.TesterStatus = false;
                        var messages = TranslateMsg.GetTranslation("DisConn", "Daemon");
                        if (!(messages == null || messages.Count == 0))
                        {
                            ClientInfo.EQPInfo.LotList[0].ShowMsg(MessageOrigin.EAP, MessageType.Error, messages[RunService.Current.ClientLanguage]);
                            Dblogger.Information("EAPClient Tip:" + messages[RunService.Current.ClientLanguage]);
                        }
                    }
                }
                //else if (eqpId.Contains("RCM"))
                //{
                //    var conn = ClientInfo.EQPInfo.RcmStatus ? "1" : "-1";
                //    if (conn == eapstatus || string.IsNullOrEmpty(eapstatus))
                //    {
                //        return;
                //    }
                //    if (eapstatus == "1")
                //    {
                //        ClientInfo.EQPInfo.RcmStatus = true;
                //        var messages = TranslateMsg.GetTranslation("Conn", "RCM");
                //        if (!(messages == null || messages.Count == 0))
                //        {
                //            ClientInfo.EQPInfo.LotList[0].ShowMsg(MessageOrigin.EAP, MessageType.Conn, messages[RunService.Current.ClientLanguage]);
                //        }
                //    }
                //    else
                //    {
                //        ClientInfo.EQPInfo.RcmStatus = false;
                //        var messages = TranslateMsg.GetTranslation("DisConn", "RCM");
                //        if (!(messages == null || messages.Count == 0))
                //        {
                //            ClientInfo.EQPInfo.LotList[0].ShowMsg(MessageOrigin.EAP, MessageType.Error, messages[RunService.Current.ClientLanguage]);
                //        }
                //    }
                //}
            }
            catch (Exception ex)
            {
                logger.Error(ex, $"ClientService.ChangeWaferColor() Execute Error.");
            }
        }
        /// <summary>
        /// 设置lot状态
        /// </summary>
        /// <param name="xfwArgs"></param>
        public void SendLotStatus(XfwArgs xfwArgs)
        {
            try
            {
                var obj = xfwArgs.NATSData.Data;
                var body = obj.GetBody();
                var eqpId = body.GetVal(CItems.EqpID);
                var lotStatus = body.GetVal(CItems.lotStatus);

                ClientInfo.EQPInfo.LotList[0].LotsStatus = lotStatus;
            }
            catch (Exception ex)
            {
                logger.Error(ex, $"ClientService.SendLotStatus() Execute Error.");
            }
        }
        public void SendWaferStatus(XfwArgs xfwArgs)
        {
            try
            {
                var obj = xfwArgs.NATSData.Data;
                var body = obj.GetBody();
                var eqpId = body.GetVal(CItems.EqpID);
                var lotStatus = body.GetVal(CItems.lotStatus);

                ClientInfo.EQPInfo.LotList[0].State = lotStatus;
            }
            catch (Exception ex)
            {
                logger.Error(ex, $"ClientService.SendLotStatus() Execute Error.");
            }
        }

    }
}
